package com.wangtongxiao.beans;

import java.io.*;

public class MyApp5 {
    public static void main(String[] args) {
//        源文件
        String pathSrc = "d:\\apache-tomcat-9.0.63.zip";
//        目的地址
        String pathDes = "D:\\系统之家\\apache-tomcat-9.0.63.zip";
        File fileDes = new File(pathDes);
        if (fileDes.exists()) {
            boolean delete = fileDes.delete();
            if (!delete) {
                System.out.println("文件为空");
                return;
            }
        }
            boolean newFile = false;

            try {
                newFile = fileDes.createNewFile();

                if (!newFile) {
                    System.out.println("文件创建失败");
                    return;
                }


            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("文件创建失败。。。。。。");
                return;
            }


        try {
            byte[] bytes = new byte[1024 * 8];
//开始获取读取文件内容
            FileInputStream inputStream = new FileInputStream(pathSrc);

            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
//            开始准备链接目的文件
            FileOutputStream fileOutputStream = new FileOutputStream(pathDes);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);

            int read = 0;
            while ((read = bufferedInputStream.read(bytes, 0, bytes.length)) != -1) {
                bufferedOutputStream.write(bytes, 0, read);
            }
            fileOutputStream.flush();
            fileOutputStream.close();
            bufferedInputStream.close();
            bufferedOutputStream.flush();
            bufferedOutputStream.close();
            inputStream.close();


        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println("文件源读取失败");
            return;
        } catch (IOException e) {
            System.out.println("文件源读取失败");
            return;
        }
    }


}
